< Prev(J) / Next(K) > / View :

Filename: /text/sbasic/shared/03090101.xhp

(section: ifthenelse) (bookmark: bm_id3154422)
If statement

If ステートメント

If...Then...Else Statement [Runtime]
If...Then...Else ステートメント [実行時](hd_id3154422.1)

Defines one or more statement blocks that you only want to execute if a given condition is True.
特定の判定条件が True で合った場合にのみ、指定したステートメントブロック (複数指定可能) を実行させます。(par_id3155555.2)

(/section: ifthenelse)

Syntax:
構文:(hd_id3146957.3)

If condition=true Then Statement block [ElseIf condition=true Then] Statement block [Else] Statement block EndIf
Instead of Else If you can write ElseIf, instead of End If you can write EndIf.

If condition=true Then Statement block [ElseIf condition=true Then] Statement block [Else] Statement block EndIf
Else If の代わりに ElseIf と書くことができ、End If の代わりに EndIf と書くことができます。
(par_id3153126.4)

Parameters:
パラメータ:(hd_id3155419.5)

The If...Then statement executes program blocks depending on given conditions. When Office Basic encounters an If statement, the condition is tested. If the condition is True, all subsequent statements up to the next Else or ElseIf statement are executed. If the condition is False, and an ElseIf statement follows, Office Basic tests the next condition and executes the following statements if the condition is True. If False, the program continues either with the next ElseIf or Else statement. Statements following Else are executed only if none of the previously tested conditions were True. After all conditions are evaluated, and the corresponding statements executed, the program continues with the statement following EndIf.
If... Then ステートメントが指定したプログラムブロックを実行するかは、与えられた判定条件によります。 Office Basic の実行行が If ステートメントに到達すると、判定条件のチェックが行われます。 判定結果が True であれば、次の Else ないし ElseIf ステートメントまでに記述されているすべてのステートメントブロックが実行されます。 判定結果が False であり ElseIf ステートメントが指定されていれば、Office Basic は次の判定条件をチェックし、その判定結果が True であれば、該当するステートメントブロックが実行されます。 判定結果が False であれば、直後の ElseIf ないし Else に従って処理が続行されます。 Else に続くステートメントブロックは、それ以前にある判定条件がすべて満たされなかった場合にのみ実行されます。 こうしたすべての判定条件が評価され、該当するステートメントブロックの実行が終了すると、EndIf 以降に記述されたステートメントが実行されます。(par_id3153062.6)

You can nest multiple If...Then statements.
If...Then ステートメントは、複数のものをネスト (入れ子化) することができます。(par_id3153192.7)

Else and ElseIf statements are optional.
Else および ElseIf は省略可能です。(par_id3154684.8)

Warning Icon 警告マーク You can use GoTo and GoSub to jump out of an If...Then block, but not to jump into an If...Then structure.
GoToGoSub を使って、If...Then の中から外へジャンプすることは可能ですが、If...Then の中にジャンプすることはできません。(par_id3152939.9)

The following example enables you to enter the expiration date of a product, and determines if the expiration date has passed.
下記の例では、製品の有効期限をユーザーに入力させて、期限が切れていないかを判定しています。(par_id3153951.10)

Example:
例:(hd_id3152576.11)

Sub ExampleIfThenDate
Sub ExampleIfThenDate(par_id3150011.12)

Dim sDate as String
Dim sDate as String(par_id3148645.13)

Dim sToday as String
Dim sToday as String(par_id3155855.14)

sDate = InputBox("Enter the expiration date (MM.DD.YYYY)")
sDate = InputBox("Enter the expiration date (MM.DD.YYYY)")(par_id3154490.16)

sDate = Right$(sDate, 4) + Mid$(sDate, 4, 2) + Left$(sDate, 2)
sDate = Right$(sDate, 4) + Mid$(sDate, 4, 2) + Left$(sDate, 2)(par_id3154943.17)

sToday = Date$
sToday = Date$(par_id3154098.18)

sToday = Right$(sToday, 4)+ Mid$(sToday, 4, 2) + Left$(sToday, 2)
sToday = Right$(sToday, 4)+ Mid$(sToday, 4, 2) + Left$(sToday, 2)(par_id3144765.19)

If sDate < sToday Then
If sDate < sToday Then(par_id3154792.20)

MsgBox "The expiration date has passed"
MsgBox "The expiration date has passed"(par_id3155601.21)

ElseIf sDate > sToday Then
ElseIf sDate > sToday Then(par_id3146972.22)

MsgBox "The expiration date has not yet passed"
MsgBox "The expiration date has not yet passed"(par_id3146912.23)

Else
Else(par_id3153710.24)

MsgBox "The expiration date is today"
MsgBox "The expiration date is today"(par_id3154754.25)

End If
End If(par_id3154361.26)

End Sub
End Sub(par_id3148405.28)


< Prev / Next >